import 'dart:math';
import 'dart:ui';

import 'package:common_utils/common_utils.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutterlib/common/style/font_awesome4_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/distance_utils.dart';
import 'package:flutterlib/common/utils/utils.dart';
import 'package:flutterlib/model/activity/activity.dart';

class ActivityListItemNewAdmin extends StatelessWidget {
  final Activity activity;

  final VoidCallback onPressed;
  final AnimationController animationController;
  final Animation<dynamic> animation;
  final VoidCallback onPassPressed;
  final VoidCallback onRejectPressed;
  final Poi myLocation;

  ActivityListItemNewAdmin(this.activity,
      {this.myLocation, this.onPressed, this.animationController, this.onPassPressed,
        this.onRejectPressed, this.animation})
      : super();

  @override
  Widget build(BuildContext context) {
    String distance = DistanceUtil.getMyDistanceFrom(myLocation,
            DistanceUtil.getPointFromStr(activity.location))
        .toString();

    return Padding(
      padding: const EdgeInsets.only(left: 10, right: 10, top: 8, bottom: 16),
      child: InkWell(
        splashColor: Colors.transparent,
        onTap: () {
          onPressed();
        },
        child: Container(
          decoration: BoxDecoration(
            borderRadius: const BorderRadius.all(Radius.circular(10.0)),
            boxShadow: <BoxShadow>[
              BoxShadow(
                color: Colors.grey.withOpacity(0.6),
                offset: const Offset(4, 4),
                blurRadius: 16,
              ),
            ],
          ),
          child: ClipRRect(
            borderRadius: const BorderRadius.all(Radius.circular(10.0)),
            child: Column(
              children: <Widget>[
                AspectRatio(
                  aspectRatio: 2,
                  child: ActivityStatus.values[activity.status] ==
                          ActivityStatus.ended
                      ? Stack(
                    fit: StackFit.expand,
                    children: [
                      ExtendedImage.network(
                          activity.logo,
                          fit: BoxFit.cover,
                        ),
                      // Container(
                      //   color: Theme.of(context).primaryColor.withOpacity(0.5),
                      //   width: double.infinity,
                      // ),
                      ClipRRect(
                        child: BackdropFilter(
                          filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
                          child: Container(
                            width: double.infinity,
                            height: 200,
                            child: Center(child: Text("已结束", style: QuhuiConstant.smallTextWhite,)),  //背景上面的其他组件
                          ),
                        ),
                      ),
                    ],

                  )
                      : ExtendedImage.network(
                          activity.logo,
                          fit: BoxFit.cover,
                        ),
                ),
                Container(
                  color: QuhuiColors.white,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Expanded(
                        child: Container(
                          child: Padding(
                            padding: const EdgeInsets.only(
                                left: 16, top: 8, bottom: 8),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                Row(
                                  children: [
                                    Expanded(
                                      child: Text(activity.aim,
                                          textAlign: TextAlign.left,
                                          style:
                                              QuhuiConstant.smallTextBold),
                                    ),
                                    Icon(
                                      Icons.local_library,
                                      color: QuhuiColors.mainThemeColor,
                                    ),
                                    Padding(
                                      padding: const EdgeInsets.fromLTRB(
                                          0, 0, 10, 0),
                                      child: Text(
                                        '距离$distance',
                                        style: QuhuiConstant.minSubText,
                                      ),
                                    )
                                  ],
                                ),
                                Row(
                                  crossAxisAlignment:
                                      CrossAxisAlignment.center,
                                  mainAxisAlignment:
                                      MainAxisAlignment.start,
                                  children: <Widget>[
                                    Text(
                                      '${DateUtil.formatDateMs(activity.startTime * 1000, format: DateFormats.y_mo_d)}' +
                                          '' +
                                          '${DateUtil.getWeekdayByMs(activity.startTime, languageCode: 'zh')}',
                                      style: QuhuiConstant.minSubText,
                                    ),
                                    const SizedBox(
                                      width: 20,
                                    ),
                                    Expanded(
                                      child: Text(
                                        activity.address,
                                        overflow: TextOverflow.ellipsis,
                                        style: QuhuiConstant.minSubText,
                                      ),
                                    ),
                                  ],
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(top: 4),
                                  child: Row(
                                    children: <Widget>[
                                      Text(
                                        '￥ ${activity.cost}',
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Colors.grey
                                                .withOpacity(0.8)),
                                      ),
                                      const SizedBox(
                                        width: 20,
                                      ),
                                      DecoratedBox(
                                        decoration: BoxDecoration(
                                          border: Border.all(
                                              color: QuhuiColors
                                                  .mainThemeColor,
                                              width: 1),
                                          borderRadius:
                                              BorderRadius.circular(8),
                                        ),
                                        child: Padding(
                                          padding:
                                              const EdgeInsets.symmetric(
                                                  vertical: 2.0,
                                                  horizontal: 8.0),
                                          child: Text(
                                            '${activity.limitPeople.toString()}人',
                                            style: QuhuiConstant
                                                .minTextThemeColor,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Row(
                                  children: <Widget>[
                                    InkWell(
                                      onTap: onPassPressed,
                                      child: Container(
                                        width: 50,
                                        height: 50,
                                        alignment: Alignment.center,
                                        child: activity.status == 0 ? Icon(
                                          AIcon.paper_plane,
                                        ) : activity.status == 1 ? Text(
                                          "通过",
                                          style: QuhuiConstant.minTextThemeColor,) : Text(
                                            ""
                                        ),
                                      ),
                                    ),
                                    InkWell(
                                      onTap: onRejectPressed,
                                      child: Container(
                                        width: 50,
                                        height: 50,
                                        alignment: Alignment.center,
                                        child: activity.status == 0 ? Icon(
                                          AIcon.sticky_note,
                                        ) : activity.status == 3 ? Text(
                                          "拒绝",
                                          style: QuhuiConstant.smallTextRedBold,) : Text(
                                            ""
                                        ),

                                      ),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
